import Vue from 'vue';
import Router, { RouteConfig } from 'vue-router';
import Layout from '@/layout/index.vue';
Vue.use(Router);
/*
  redirect:                      if set to 'noredirect', no redirect action will be trigger when clicking the breadcrumb
  meta: {
    title: 'title'               the name showed in subMenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon showed in the sidebar
    breadcrumb: false            if false, the item will be hidden in breadcrumb (default is true)
    hidden: true                 if true, this route will not show in the sidebar (default is false)
  }
*/
export const constantRoutes: RouteConfig[] = [
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "login" */ '@/views/login/index.vue'),
    meta: { hidden: true }
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue'),
    meta: { hidden: true }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard', // 确保名字是唯一的
        component: () => import(/* webpackChunkName: "dashboard" */ '@/views/dashboard/index.vue'),
        meta: {
          title: '管理首页',
          icon: 'back-top'
        }
      }
    ]
  }
];
export const asyncRoutes: RouteConfig[] = [
  {
    path: '/agent',
    component: Layout,
    redirect: '/agent/agent',
    meta: { icon: 'tree', name: '代理管理' },
    children: [
      {
        path: '/agent',
        component: () => import('@/views/agent/index.vue'),
        meta: { title: '代理管理', icon: 'tree', name: '代理管理' }
      }
    ]
  },
  {
    path: '/customer',
    component: Layout,
    redirect: '/customer/customer',
    meta: { icon: 'people', name: '客服管理' },
    children: [
      {
        path: '/customer',
        component: () => import('@/views/customer/index.vue'),
        meta: { title: '客服管理', icon: 'people', name: '客服管理' }
      }
    ]
  },
  {
    path: '/direct',
    component: Layout,
    redirect: '/direct/direct',
    meta: {
      name: '直属用户',
      icon: 'user'
    },
    children: [
      {
        path: '/direct/direct',
        component: () => import('@/views/direct/index.vue'),
        meta: {
          title: '直属用户',
          name: '直属用户',
          icon: 'user'
        }
      }
    ]
  },
  {
    path: '/junior',
    component: Layout,
    redirect: '/junior/junior',
    meta: {
      name: '下属用户',
      icon: 'peoples'
    },
    children: [
      {
        path: '/junior/junior',
        component: () => import('@/views/junior/index.vue'),
        meta: {
          title: '下属用户',
          name: '下属用户',
          icon: 'peoples'
        }
      }
    ]
  },
  {
    path: '/game',
    component: Layout,
    redirect: '/game/game',
    meta: {
      name: '游戏分类',
      icon: 'component'
    },
    children: [
      {
        path: '/game/game',
        component: () => import('@/views/game/index.vue'),
        meta: {
          title: '游戏分类',
          name: '游戏分类',
          icon: 'component'
        }
      }
    ]
  },
  {
    path: '/reward',
    component: Layout,
    redirect: '/reward/reward',
    meta: {
      name: '奖励设置',
      icon: 'like'
    },
    children: [
      {
        path: '/reward/reward',
        component: () => import('@/views/reward/index.vue'),
        meta: {
          title: '奖励设置',
          name: '奖励设置',
          icon: 'like'
        }
      }
    ]
  },
  {
    path: '/member',
    component: Layout,
    redirect: '/member/member',
    meta: {
      name: '会员权益',
      icon: 'guide'
    },
    children: [
      {
        path: '/member/member',
        component: () => import('@/views/member/index.vue'),
        meta: {
          title: '会员权益',
          name: '会员权益',
          icon: 'guide'
        }
      }
    ]
  },
  {
    path: '/shop',
    component: Layout,
    redirect: '/shop/shop',
    meta: {
      name: '礼物商城',
      icon: 'guide'
    },
    children: [
      {
        path: '/shop/shop',
        component: () => import('@/views/shop/index.vue'),
        meta: {
          title: '礼物商城',
          name: '礼物商城',
          icon: 'guide'
        }
      }
    ]
  },
  {
    path: '/record',
    component: Layout,
    redirect: '/record/record',
    meta: {
      name: '操作记录',
      icon: 'table'
    },
    children: [
      {
        path: '/record/record',
        component: () => import('@/views/record/index.vue'),
        meta: {
          title: '操作记录',
          name: '操作记录',
          icon: 'table'
        }
      }
    ]
  },
  {
    path: '*',
    redirect: '/404',
    meta: { hidden: true }
  }
];
export default new Router({
  mode: 'hash', // 改为 hash 模式
  scrollBehavior: (to, from, savedPosition) => {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  },
  base: process.env.BASE_URL,
  routes: constantRoutes
});
